﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Structure.Interfaces;

namespace Storage
{
    internal class SqlConnect : iSqlConnect
    {
        private string _ServerName;
        private string _DBName;
        private string _UserName;
        private string _UserPassword;

        public SqlConnect()
        {
            ServerName = "YEGOR-NB\\SQLEXPRESS";
            DBName = "DB";
            UserName = "YEGOR-NB\\Yegor";
            UserPassword = " ";
        }

        public SqlConnect(string servername, string dbname, string username, string userpassword)
        {
            ServerName = servername;
            DBName = dbname;
            UserName = username;
            UserPassword = userpassword;
        }

        public string ServerName
        {
            get { return _ServerName; }
            set { _ServerName = value; }
        }

        public string DBName
        {
            get { return _DBName; }
            set { _DBName = value; }
        }

        public string UserName
        {
            get { return _UserName; }
            set { _UserName = value; }
        }

        public string UserPassword
        {
            get { return _UserPassword; }
            set { _UserPassword = value; }
        }

        public SqlConnection OpenConnection()
        {
            string connectionString = String.Format("server = '{0}'; database = '{1}'; Integrated Security = true; User ID= '{2}' ;Password = '{3}' ", _ServerName, _DBName, _UserName, _UserPassword);
            SqlConnection  _connection = new SqlConnection(connectionString);
            _connection.Open();
            return _connection;
        }

        public void CloseConnection(SqlConnection _connection)
        {
            _connection.Close();
        }
    }
}
